/*
 * SR04.c
 *
 *  Created on: Sep 10, 2025
 *      Author: lianz
 */

#include "tim.h"
#include "SR04.h"
#include "stm32f1xx_hal.h"
#include "pid.h"

volatile uint16_t count;
volatile float distance;

void RCCdelay_us(uint32_t udelay)
{
  __IO uint32_t Delay = udelay * 72 / 8;//(SystemCoreClock / 8U / 1000000U)
    //¼ûstm32f1xx_hal_rcc.c -- static void RCC_Delay(uint32_t mdelay)
  do
  {
    __NOP();
  }
  while (Delay --);
}

void Get_Distance(void)
{
	HAL_GPIO_WritePin(SR04_SEND_GPIO_Port, SR04_SEND_Pin, SET);
	RCCdelay_us(12);
	HAL_GPIO_WritePin(SR04_SEND_GPIO_Port, SR04_SEND_Pin, RESET);
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if (GPIO_Pin == GPIO_PIN_5)
	{
		Control();
	}


}










